<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<%@ include file="../common/include/header.jsp"%>

<div>
<table border="0" cellpadding="0" cellspacing="0" width="980px">
	<tr>
		<td style="vertical-align: top;width: 180px;background-color: #fdb73a;">
			<%@ include file="../common/include/leftmenu.jsp" %>
		</td>
	<html:form action="/photoboard" enctype="multipart/form-data">
		<td style="text-align: center;width: 800px; vertical-align: top;">
		
			<%@include file="logo.jsp" %>
			
			<div class="boardname">	<bean:write name="photoForm" property="pbname"/></div>

		<input type="hidden" name="method" value="photoInsert"/>
			
			<table style="width: 700px" cellpadding="0" cellspacing="0" >
				<tr><td style="width: 100px;text-align: center;">작성자</td>
					<td style="text-align: left;width: 580px;"><bean:write name="user" property="mcnick"/></td></tr>
				<tr><td style="width:100px;text-align: center;">제목</td>
					<td style="text-align: left;width: 580px;"><html:text property="pbtitle" onchange="submitCheck()" maxlength="30" style="width: 500px;"/></td>
				</tr>
				<tr><td colspan="2" style="height: 300px;"><html:textarea property="pbcontent" cols="50" rows="15"/></td>
				</tr>
				<tr>
					<td width="100px">파일 첨부</td>
					<td align="left">
						<html:file property="formFile" size="50" onchange="fileCheck(this.value)"/><font style="font-size: 7pt;">(JPG, GIF, PNG)</font>
					</td>
				</tr>
			</table>
			<div id="viewPhoto" style="display: none">
			<table border="0" cellpadding="0" cellspacing="0" width="700px">
				<tr>
					<td colspan="2"><html:img src="" imageName="imgbox" style="display: none" onclick="changeSize()"/></td>
				</tr>
				
			</table>
			</div>

					<html:hidden property="pbwidth"/>
					<html:hidden property="pbheight"/>
					<html:hidden property="viewWidth"/>
					<html:hidden property="viewHeight"/>
			
		<input type="hidden" name="cono" value="<bean:write name="photoForm" property="cono"/>"/>
		<input type="hidden" name="pbname" value="<bean:write name="photoForm" property="pbname"/>"/>
			
			<div style="padding-top: 10px;padding-bottom: 10px;">
			<a href="javascript:validate()" id="submitButton" style="display: none"><img src="<%=imagePath %>icon_confirm.jpg"/></a>
			<a href="javascript:history.go(-1);"><img src="<%=imagePath %>icon_list.jpg"/></a></div>
		</td>
	</html:form>
	</tr>
</table>
</div>

<%@ include file="../common/include/footer.jsp"%>

<script type="text/javascript" src="<%=path %>/fckeditor/fckeditor.js"> </script>
<script type="text/javascript">
	window.attachEvent("onload", getfckeditor);
	 function getfckeditor(){
		var oFCKeditor = new FCKeditor( 'pbcontent' ) ;
		oFCKeditor.BasePath	= "<%=path%>/fckeditor/" ;
		oFCKeditor.ReplaceTextarea() ;
	}
</script>

<script type="text/javascript">
<!--
	//파일의 확장자를 구하는 스크립트///////////////////////////////
	function getFileExtension(filePath){
	    var lastIndex = -1;
	    lastIndex = filePath.lastIndexOf('.');
	    var extension = "";
	
		if(lastIndex != -1){
		    extension = filePath.substring(lastIndex + 1, filePath.len);
		}else{
		    extension = "";
		}
		return extension;
	}
	
	//이미지 파일만 걸러주는 스크립트//////////////////////////////////
	function fileCheck(value){
	    var src = getFileExtension(value);
	    if(!((src.toLowerCase()=="jpg") || (src.toLowerCase()=="jpeg") || (src.toLowerCase()=="gif") || (src.toLowerCase()=="png"))){
	        document.getElementById("submitButton").style.display = "none";
	        alert("JPG, JPEG, GIF, PNG 파일만 올려주세요~!");
	        return;
	    }
	    view(value);
	}
	
	//사진 크기조절과 원래 사이즈 및 조절된 사이즈를 구하는 스크립트/////////////////
	var image = new Image();
	var xsize = 0;
	var ysize = 0;
	
	function view(src){
		document.getElementById("imgbox").src = "";
		image.src = "";
		image.width = 0;
		image.height = 0;
		
		image.src = src;
		document.getElementById("viewPhoto").style.display = "";
		
		var setSize = 100;
		document.images.onload = view2(setSize);
	}
	
	function view2(setSize){
	
		xsize = image.width;
		ysize = image.height;
		var setsize = setSize;

		if(xsize > setsize || ysize > setsize){
			if(xsize > ysize){
				document.images.imgbox.width = setsize;
				document.images.imgbox.height = ysize * setsize / xsize;
			}else{
				document.images.imgbox.width = xsize * setsize / ysize;
				document.images.imgbox.height = setsize;
			}
		}else{
			document.images.imgbox.width = xsize;
			document.images.imgbox.height = ysize;
		}
		
		document.images.imgbox.src = image.src;
		document.images.imgbox.style.display = "";
		
		document.getElementById("pbwidth").value = xsize;
		document.getElementById("pbheight").value = ysize;
		document.getElementById("viewWidth").value = document.images.imgbox.width;
		document.getElementById("viewHeight").value = document.images.imgbox.height;
		
		submitCheck();
	}
	
	//사진을 클릭했을때 크기변화시키는 스크립트////////////////////////
	var i = 0;
	function changeSize(){
		if(i==0){
			view2(500);
			i = 1;
		}else{
			view2(100);
			i = 0;
		}
	}
	
	//등록가능 여부를 체크해서 버튼사용 가능유무를 컨드롤하는 스크립트//////////////
	function submitCheck(){
		var title = document.getElementById("pbtitle").value;
		var photo = document.getElementById("formFile").value;
		if(title!="" && photo!=""){
			document.getElementById("submitButton").style.display="";
		}else{
			document.getElementById("submitButton").style.display="none";
		}
	}
	
	function validate(){
		document.getElementById("photoForm").submit();
	}

//-->
</script>
